package com.ming.easyDevelop.service.impl;

import com.ming.easyDevelop.mappers.UserCouponsMapper;
import com.ming.easyDevelop.entity.po.UserCoupons;
import com.ming.easyDevelop.entity.query.UserCouponsQuery;
import java.util.List;
import org.springframework.stereotype.Service;
import com.ming.easyDevelop.service.UserCouponsService;
import com.ming.easyDevelop.entity.vo.PaginationResVo;
import java.util.Date;
import com.ming.easyDevelop.entity.baseEnum.PageSize;
import com.ming.easyDevelop.entity.query.base.SimplePage;
@Service("userCouponsService")
public class UserCouponsServiceImpl implements UserCouponsService {
	private final UserCouponsMapper<UserCoupons, UserCouponsQuery> userCouponsMapper;

	public UserCouponsServiceImpl(UserCouponsMapper userCouponsMapper){
		this.userCouponsMapper = userCouponsMapper;
	}
	/**
	 * 根据条件查询列表
	 */
	@Override
	public List<UserCoupons> findListByParam(UserCouponsQuery query){
		return this.userCouponsMapper.selectList(query);
	}

	/**
	 * 根据条件查询数量
	 */
	@Override
	public Long findCountByParam(UserCouponsQuery query){
		return this.userCouponsMapper.selectCount(query);
	}

	/**
	 * 根据条件分页查询列表
	 */
	@Override
	public PaginationResVo<UserCoupons> findListByPage(UserCouponsQuery query){
		Long count = this.findCountByParam(query);
		int pageSize = query.getPageSize() == null ? PageSize.SIZE20.getSize() : query.getPageSize();
		SimplePage simplePage = new SimplePage(query.getPageNo(), pageSize, Math.toIntExact(count));
		List<UserCoupons> res = this.findListByParam(query);
		return new PaginationResVo<UserCoupons>(query.getSimplePage().getPageNo(), query.getSimplePage().getPageSize(), query.getSimplePage().getCountTotal(), query.getSimplePage().getPageTotal(), res);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Long addBatch(List<UserCoupons> list){
		return this.userCouponsMapper.insertBatch(list);
	}

	/**
	 * 新增
	 */
	@Override
	public Long add(UserCoupons bean){
		return this.userCouponsMapper.insert(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdate(UserCoupons bean){
		return this.userCouponsMapper.insertOrUpdate(bean);
	}

	/**
	 * 新增
	 */
	@Override
	public Long addOrUpdateBatch(List<UserCoupons> list){
		return this.userCouponsMapper.insertOrUpdateBatch(list);
	}

	/**
	 * 根据UserIDAndCouponCode查询
	 */
	@Override
	public UserCoupons getByUserIDAndCouponCode(Integer userID, String couponCode){
		return this.userCouponsMapper.selectByUserIDAndCouponCode(userID, couponCode);
	}

	/**
	 * 根据UserIDAndCouponCode更新
	 */
	@Override
	public Long updateByUserIDAndCouponCode(UserCoupons bean, Integer userID, String couponCode){
		return this.userCouponsMapper.updateByUserIDAndCouponCode(bean,userID, couponCode);
	}

	/**
	 * 根据UserIDAndCouponCode删除
	 */
	@Override
	public Long deleteByUserIDAndCouponCode(Integer userID, String couponCode){
		return this.userCouponsMapper.deleteByUserIDAndCouponCode(userID, couponCode);
	}

}
